package com.kjj.basic.service.impl;

import com.kjj.basic.service.IBaiduAiService;
import com.kjj.basic.util.AjaxResult;
import com.kjj.basic.util.AuthService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class BaiduAiServiceImpl implements IBaiduAiService {
    @Override
    public AjaxResult audit(String text, String imgUrl, String videoUrl) {
        AjaxResult result = AjaxResult.me();
        StringBuilder sb = new StringBuilder();
        if (text!=null){
            if (!StringUtils.isEmpty(text.trim())) {
                Map<String, Object> textAuditResult = AuthService.TextCensor(text);
                Boolean success = (Boolean) textAuditResult.get("success");
                String message = (String) textAuditResult.get("message");
                if (!success) {
                    result.setSuccess(false);
                    sb.append(text+":"+message);
                }
            }
        }

        if (imgUrl!=null){
            if (!StringUtils.isEmpty(imgUrl.trim())) {
                Map<String, Object> textAuditResult = AuthService.TextCensor(imgUrl);
                Boolean success = (Boolean) textAuditResult.get("success");
                String message = (String) textAuditResult.get("message");
                if (!success) {
                    result.setSuccess(false);
                    sb.append(message);
                }
            }
        }
        if (!result.isSuccess()){
            result.setMessage(sb.toString());
        }
        return result;
    }
}
